package com.csii.adhoc.dataready.serviceImpl;

import com.csii.adhoc.dataready.TDataConstant;
import com.csii.adhoc.dataready.TDataRelationDtlPo;
import com.csii.adhoc.dataready.mapper.TDataRelationDtlMapper;
import com.csii.adhoc.dataready.service.TDataRelationDtlService;
import com.csii.adhoc.exception.ParamValidityException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @description: 数据集接口实现类
 * @author: zyliu
 * @create: 2021-01-13 09:32
 */
@Service("tDataRelationDtlService")
@Slf4j
public class TDataRelationDtlServiceImpl implements TDataRelationDtlService {

    @Autowired
    TDataRelationDtlMapper tDataRelationDtlMapper;

    @Override
    @Transactional
    public void tDataRelationDtlMaintain(TDataRelationDtlPo tDataRelationDtlPo, String optMode) {
        switch (optMode) {
            case TDataConstant.OPT_MODE_UPDATE:
                updateTDataRelationDtlByPrimaryKey(tDataRelationDtlPo);
                break;
            case TDataConstant.OPT_MODE_DELETE:
                deleteByRelationId(tDataRelationDtlPo.getRelationId());
                break;
            default:
                log.error("optMode值不合法:" + optMode);
                throw new ParamValidityException("操作标志不合法:" + optMode);
        }
    }

    @Transactional
    @Override
    public void insertListTDataRelationDtl(List<TDataRelationDtlPo> tdrdps) {
        tDataRelationDtlMapper.insertListTDataRelationDtl(tdrdps);
    }
    @Transactional
    @Override
    public void insertOneTDataRelationDtl(TDataRelationDtlPo tDataRelationDtlPo) {
        tDataRelationDtlMapper.insertOneTDataRelationDtl(tDataRelationDtlPo);
    }

    @Transactional
    @Override
    public int updateTDataRelationDtlByPrimaryKey(TDataRelationDtlPo tDataRelationDtlPo) {
        return tDataRelationDtlMapper.updateByPrimaryKey(tDataRelationDtlPo);
    }

    @Transactional
    @Override
    public int deleteByRelationId(String relationId) {
        return tDataRelationDtlMapper.deleteByRelationId(relationId);
    }

    @Transactional
    @Override
    public int deleteTDataRelationDtlByPrimaryKey(String relationId,String masterId,String slaveId) {
        return tDataRelationDtlMapper.deleteByPrimaryKey(relationId,masterId,slaveId);
    }

    @Override
    public List<TDataRelationDtlPo> selectListTDataRelationDtl(String modelId) {
        return tDataRelationDtlMapper.selectListTDataRelationDtl(modelId);
    }

    @Override
    public List<TDataRelationDtlPo> selectListTDataRelationDtlByIds(List list) {
        return tDataRelationDtlMapper.selectListTDataRelationDtlByIds(list);
    }

    @Override
    public List<Map<String,String>> selectTableIdByModelId(String modelId) {
        return tDataRelationDtlMapper.selectTableIdByModelId(modelId);
    }

    @Override
    public TDataRelationDtlPo selectOneTDataRelationDtl(String modelId,String fldEnname) {
        return tDataRelationDtlMapper.selectOneTDataRelationDtl(modelId,fldEnname);
    }
    @Override
    public Map selCustDataDbTable(String sql){
        return tDataRelationDtlMapper.selCustDataDbTable(sql);
    }
}
